package cn.edu.scau.cmi.dengshixin.singleton;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class Controller {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button singletonButton;

    @FXML
    private Button multitonButton;

    @FXML
    private TextField inputText;

    @FXML
    private Label showLabel;

    @FXML
    private TextArea showArea;

    @FXML
    void singleAdd(ActionEvent event) {
    	String name = inputText.getText();
    	inputText.clear();
    	if(!name.equals("")) {
    		Chairman chairman = Chairman.getInstance(name);
    		showLabel.setText(chairman.getName() + chairman);
    	}
    	else {
    		showLabel.setText("请输入主席名！");
    	}
    }

    @FXML
    void multipleAdd(ActionEvent event) {
    	String name = inputText.getText();
    	inputText.clear();
    	if(!name.equals("")) {
    		Marshal marshal = new Marshal(name);
    		if(Marshal.getTotal() < 10)
    			showArea.appendText(marshal.getName() + marshal + "\n");
    		else
    			showArea.appendText("你已经创建了10个元帅了，不能再创建了！\n");
    	}
    }

    @FXML
    void initialize() {
        assert singletonButton != null : "fx:id=\"singletonButton\" was not injected: check your FXML file 'SingletonFX.fxml'.";
        assert multitonButton != null : "fx:id=\"multitonButton\" was not injected: check your FXML file 'SingletonFX.fxml'.";
        assert inputText != null : "fx:id=\"inputText\" was not injected: check your FXML file 'SingletonFX.fxml'.";
        assert showLabel != null : "fx:id=\"showLabel\" was not injected: check your FXML file 'SingletonFX.fxml'.";
        assert showArea != null : "fx:id=\"showArea\" was not injected: check your FXML file 'SingletonFX.fxml'.";

    }
}

